<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <link href="/static/layui/css/layui.css" rel="stylesheet">

    <link href="/static/css/left.css" rel="stylesheet">

    <style>
        body{
            background-color: #fafafa;
        }

        .right_content{
            width: 900px;
            background-color: #ffff;
            padding: 3%;
            min-height: 600px;
        }
        .right_content div{
            padding: 1% 0px;
        }
        .title_content span{
            font-size: 20px;
            font-weight: 600;
        }
        .layui-btn.layui-bg-blue{
            background-color: #276040 !important;
        }
        .layui-table thead tr th{
            border-left: solid 1px #ffffff !important;
            border-top: solid 1px #ffffff !important;
            border-right: solid 1px #ffffff !important;
            background-color: #fafafa;
            padding: 0px 25px !important;
            height: 50px ;

        }
        .layui-table tbody tr td{
            border-left: solid 1px #ffffff !important;
            border-right: solid 1px #ffffff !important;
            border-: solid 1px #ffffff !important;
            padding: 0px 25px !important;
            height: 50px;
            color: #a9a9a9 !important;
        }

        tbody tr td button{
            border-color: #276040 !important;;
            color: #276040 !important;
            border-radius: 5px !important;

        }

    </style>

</head>
<body>

   <div th:replace="/navigation_bar/top :: headerFragment"></div>
    <div class="content" style="max-width: 1220px; display: flex;margin: 0 auto;padding: 2% 0;justify-content: space-between;">

        <div th:replace="/navigation_bar/left :: left_layout"></div>
        <div class="right_content">
            <div class="title_content"><span>用户管理</span></div>
            <div class="type_content">
                <button class="layui-btn layui-bg-blue" onclick="user_info()">新增用户</button>
            </div>
            <!--<div class="query_content"></div>-->
            <div class="table_content">
                <table class="layui-table"><colgroup>
                        <col width="150">
                        <col width="150">
                        <col width="80">
                    </colgroup>
                    <thead>
                        <tr>
                            <th>账号</th>
                            <th>姓名</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody id="tbody">
                        <!--<tr>
                            <td>孔子</td>
                            <td>华夏</td>
                            <td>
                                <button class="layui-btn layui-btn-primary layui-btn-sm">修改</button>
                                <button class="layui-btn layui-btn-primary layui-btn-sm">删除</button>
                            </td>
                        </tr>-->

                    </tbody>
                </table>
            </div>
        </div>
    </div>
<script src="/static/layui/layui.js"></script>
<script src="/static/js/jquery-2.2.2.min.js"></script>
<script src="/static/js/left.js"></script>
<script>


    $.ajax({
        url: '/user/all',// 上传地址
        type: 'POST',
        data: {param: ""},
        cache: false,//不启用缓存
        dataType: "json",//返回json格式的数据
        success: function (data) {
            //$('#tbody').children().remove()
            set_table_data(data.data);
        }
    })
    function set_table_data(data){

        let html = "";
        for (k in data){
            let item = data[k]
            html += `
                        <tr>
                            <td>`+item.name+`</td>
                            <td>`+item.fullName+`</td>
                            <td>
                                <button class="layui-btn layui-btn-primary layui-btn-sm" onclick="edit('`+item.id+`')">修改</button>
                                <button class="layui-btn layui-btn-primary layui-btn-sm" onclick="del('`+item.id+`', this)">删除</button>
                            </td>
                        </tr>
            `
        }
        $('#tbody').append(html)
    }

    function del(id,e){
        debugger
        $.ajax({
            url: '/user/delete',// 上传地址
            type: 'POST',
            data: {id: id},
            cache: false,//不启用缓存
            dataType: "json",//返回json格式的数据
            success: function (data) {
                if (data.success){
                    $(e).parent().parent().remove();
                }

            }
        })
    }

    function edit(id){
        debugger
        window.location.href="/user/edit/"+id
    }

    function user_info(){
        window.location.href="/user/info"
    }





</script>
</body>
</html>